package com.extension.company.presenter.home;

import android.content.Context;

import com.extension.company.common.mvp.BasePresenter;
import com.extension.company.contract.home.OnlineWaitForPaymentContract;
import com.extension.company.model.entity.OrderConfirmCarListBean;
import com.extension.company.model.home.OnlineWaitForPayActivityModel;

/**
 * 作者:zwk
 * 联系方式：497981239@qq.com
 * 时间：on 2019/8/6 08:52
 * 功能：
 */
public class OnlineWaitForPayActivityPresenter extends BasePresenter<OnlineWaitForPaymentContract.model, OnlineWaitForPaymentContract.View> {

	@Override
	public OnlineWaitForPaymentContract.model createModel() {
		return new OnlineWaitForPayActivityModel();
	}

	@Override
	protected void onViewDestroy() {

	}


	/**
	 * 获取默认的收货地址
	 */
	public void getDefaultAddress() {
		model.requestDefaultAddress(new OnlineWaitForPaymentContract.DefaultAddressCallbak() {
			@Override
			public void m2p(String phone, String detailAddress, String receiverName) {
				if (null != getView()) {
					getView().defaultAddress(phone, detailAddress, receiverName);
				}
			}
		});

	}

	/**
	 * 支付订单
	 */
	public void payForOrder(Context context, String goodId, String goods_spec_id, String num) {
		model.payForOrder(context, goodId, goods_spec_id, num, new OnlineWaitForPaymentContract.PayForOrderIdCallback() {
			@Override
			public void orderIdCallback(String id) {
				if (null != getView()) {
					getView().orderId(id);
				}
			}
		});
	}

	/**
	 * 请求获取是否存在默认的收货地址
	 *
	 * @param goodsInfo
	 * @param areaId
	 */
	public void orderConfirmCarList(String goodsInfo, String areaId) {
		model.orderConfirmCarList(goodsInfo, areaId, new OnlineWaitForPaymentContract.OrderConfirmListCallback() {
			@Override
			public void orderConfirmCallback(OrderConfirmCarListBean.DataBeanX mDataBeanX) {
				if (null != getView()) {
					if (null != mDataBeanX.getData().getExist_address()) {
						getView().orderDefaultAddress(mDataBeanX.getData(),true);
					}else {
						getView().orderDefaultAddress(null,false);
					}
				}
			}
		});
	}

}
